<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GET_SERVICE_MOBILES command Example :: Master-Unlock API</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
</head>

<body>
<h1>GET_SERVICE_MOBILES</h1>
<?php
	/* Include the library */
	require('../library/api.php');
	
	/**
	 * First, let's search for a service that needs the mobile phone model
	 */

	$found = FALSE;
	
	/* Call the API */
	$xml = MasterUnlock::CallAPI('GET_SERVICES');
	if (is_string ($xml)) {
		/* Parse the XML stream */
		$data = MasterUnlock::ParseXML($xml);
		
		if (is_array ($data)) {
			if (isset($data['ERROR_MESSAGE'])) {
				/* The API has returned an error */
				print ('API error : ' . htmlspecialchars ($data['ERROR_MESSAGE']));
			} else {
				/* Everything works fine */
				foreach ($data['GROUP'] as $group) {
					foreach ($group['SERVICE'] as $service) {
						if ($service['REQUIRE_MODEL'] != 'NONE') {
							/* We found a candidate for GET_SERVICE_MOBILES command */
							$found = TRUE;
							break 2;
						}
					}
				}
			}
		}
		else {
			/* Parsing error */
			print ('Could not parse the XML stream');
		}
	}
	else {
		/* Communication error */
		print ('Could not communicate with the api');
	}

	/*
	 * Now, let's call GET_SERVICE_MOBILES for this tool
	 * ============================================
	 */
	if ($found) {
		print ('<p>List of the mobile phones supported by the service <b>' . htmlspecialchars ($service['NAME']) . '</b></p>');

		/* Call the API */
		$xml = MasterUnlock::CallAPI('GET_SERVICE_MOBILES', array('SERVICE_ID' => $service['ID']));
		if (is_string ($xml)) {
			/* Parse the XML stream */
			$data = MasterUnlock::ParseXML($xml);
			
			if (is_array($data)) {
				if (isset($data['ERROR_MESSAGE'])) {
					/* The API has returned an error */
					print ('API error : ' . htmlspecialchars ($data['ERROR_MESSAGE']));
				}
				else {
					/* Everything works fine */
					foreach ($data['MOBILE'] as $Mobile) {
						print (htmlspecialchars ($Mobile['NAME']));
						print ('<br />');
					}
				}
			} else {
				/* Parsing error */
				print ('Could not parse the XML stream');
			}
		}
		else {
			/* Communication error */
			print ('Could not communicate with the api');
		}
	}
?>
<p><a href="./">Go back</a></p>
</body>
</html>